/*
 * TambahTeman.java
 *
 * Created on 12 April 2008, 14:48
 */
package usu.buku.telepon.admin;

import java.awt.event.ActionListener;
import usu.buku.telepon.data.DefaultTeman;
import usu.buku.telepon.data.template.Teman;
import usu.buku.telepon.exception.DataNotCompleteException;
import usu.buku.telepon.widget.Panel;

/**
 *
 * @author  usu
 */
public class UbahTeman extends Panel {

    private static final long serialVersionUID = -1;
    private Teman teman;

    /** Creates new form BeanForm */
    public UbahTeman() {
        initVariables();
        initComponents();
    }

    /**
     * 
     * @param l
     */
    public void addActionListenerBatal(ActionListener l) {
        buttonBatal.addActionListener(l);
    }

    /**
     * 
     * @param l
     */
    public void addActionListenerUbah(ActionListener l) {
        butttonTambah.addActionListener(l);
    }

    /**
     * 
     * @return
     * @throws usu.buku.telepon.exception.DataNotCompleteException
     */
    public Teman getTeman() throws DataNotCompleteException {
        if (textNama.getText().trim().equals("")) {
            throw new DataNotCompleteException("nama masih kosong");
        }
        if (textTelepon1.getText().equals("") && textTelepon2.getText().equals("") && textTelepon3.getText().equals("")) {
            throw new DataNotCompleteException("minimal teman harus memiliki satu nomber telepon");
        }
        teman.setNama(textNama.getText());
        teman.setTelepon1(textTelepon1.getText());
        teman.setTelepon2(textTelepon2.getText());
        teman.setTelepon3(textTelepon3.getText());
        teman.setKeterangan(textCatatan.getText());
        return teman;
    }

    /**
     * 
     * @param teman
     */
    public void setTeman(Teman teman) {
        textNama.setText(teman.getNama());
        textTelepon1.setText(teman.getTelepon1());
        textTelepon2.setText(teman.getTelepon2());
        textTelepon3.setText(teman.getTelepon3());
        textCatatan.setText(teman.getKeterangan());
        this.teman = teman;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        usu.buku.telepon.widget.Label label1 = new usu.buku.telepon.widget.Label();
        usu.buku.telepon.widget.Label label2 = new usu.buku.telepon.widget.Label();
        usu.buku.telepon.widget.Label label3 = new usu.buku.telepon.widget.Label();
        usu.buku.telepon.widget.Label label4 = new usu.buku.telepon.widget.Label();
        usu.buku.telepon.widget.Label label5 = new usu.buku.telepon.widget.Label();
        usu.buku.telepon.widget.Label label6 = new usu.buku.telepon.widget.Label();
        textNama = new usu.buku.telepon.widget.TextBox();
        textTelepon1 = new usu.buku.telepon.widget.TextBox();
        textTelepon2 = new usu.buku.telepon.widget.TextBox();
        textTelepon3 = new usu.buku.telepon.widget.TextBox();
        usu.buku.telepon.widget.ScrollPane scrollPane1 = new usu.buku.telepon.widget.ScrollPane();
        textCatatan = new usu.buku.telepon.widget.TextArea();
        butttonTambah = new usu.buku.telepon.widget.Button();
        buttonBatal = new usu.buku.telepon.widget.Button();

        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 3));

        label1.setText("Ubah Teman");
        label1.setFont(new java.awt.Font("Tahoma", 1, 24));

        label2.setDisplayedMnemonic('N');
        label2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        label2.setText("nama :");

        label3.setDisplayedMnemonic('1');
        label3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        label3.setText("telepon 1 :");

        label4.setDisplayedMnemonic('2');
        label4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        label4.setText("telepon 2 :");

        label5.setDisplayedMnemonic('3');
        label5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        label5.setText("telepon 3 :");

        label6.setDisplayedMnemonic('C');
        label6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        label6.setText("catatan :");

        textNama.setFocusAccelerator('N');

        textTelepon1.setFocusAccelerator('1');

        textTelepon2.setFocusAccelerator('2');

        textTelepon3.setFocusAccelerator('3');

        textCatatan.setColumns(20);
        textCatatan.setRows(5);
        textCatatan.setFocusAccelerator('C');
        scrollPane1.setViewportView(textCatatan);

        butttonTambah.setMnemonic('U');
        butttonTambah.setText("ubah");

        buttonBatal.setMnemonic('B');
        buttonBatal.setText("batal");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textTelepon2, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(label6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(label5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(scrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
                            .addComponent(textTelepon3, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(label2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(label3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(textTelepon1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
                            .addComponent(textNama, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(buttonBatal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(butttonTambah, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textTelepon1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textTelepon2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textTelepon3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(scrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(butttonTambah, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonBatal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    usu.buku.telepon.widget.Button buttonBatal;
    usu.buku.telepon.widget.Button butttonTambah;
    usu.buku.telepon.widget.TextArea textCatatan;
    usu.buku.telepon.widget.TextBox textNama;
    usu.buku.telepon.widget.TextBox textTelepon1;
    usu.buku.telepon.widget.TextBox textTelepon2;
    usu.buku.telepon.widget.TextBox textTelepon3;
    // End of variables declaration//GEN-END:variables

    private void initVariables() {
        teman = new DefaultTeman();
    }
}
